package com.liyu.controller;

import com.liyu.config.DirectComment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 李誉
 * @date 2022-07-04 22:17
 * @description
 */
@Slf4j
@RestController
@RequestMapping("direct")
public class DirectController {

    @Resource
    private RabbitTemplate rabbitTemplate;

    @GetMapping("{msg}")
    public void send(@PathVariable("msg") String msg) {
        rabbitTemplate.convertAndSend(DirectComment.DIRECT_EXCHANGE, DirectComment.DIRECT_RK, msg);
        log.info("消息发送成功，交换机：{}，路由：{}，消息：{}", DirectComment.DIRECT_EXCHANGE, DirectComment.DIRECT_RK, msg);
    }
}
